import {Map, View} from "@tarojs/components";
import Taro from "@tarojs/taro";
import './index.scss'
import {useEffect, useState} from "react";

function Index() {

// 设置起点终点坐标
  const setMapItemMarkers=(longitude, latitude)=> {
      var obj_item = {
        iconPath: "/img/seat.png",
        id: 0,
        longitude: longitude,
        latitude: latitude,
        width: 30,
        height: 30
      };
      var circles_aa = {
        latitude: latitude,
        longitude: longitude,
        color: '#FF0000DD',
        fillColor: '#7cb5ec88',
        radius: 160,
        strokeWidth: 1
      }
      var circles =  [];


      var markers =  [];
      markers.push(obj_item);
      circles.push(circles_aa);

    }
  const [state,setState] = useState({
    lang:'3',
    latitude: 23.099994,//经度
    longitude: 113.324520//维度
  })

  useEffect(()=>{
    mapInit()
  })

  //点击确认
  // const addHandler =()=>{
  //   Taro.navigateBack()
  // }
  //地图
  const mapInit=()=>{
    console.log('-------------------')
    const MapContext = Taro.createMapContext('myMap')
    setMapItemMarkers(state.longitude, state.latitude)
    // MapContext.moveToLocation( {
    //   latitude: 23.099994,
    //   longitude: 113.324520
    // } )
    //设置地图容器
    console.log('设置地图容器成功',MapContext)
  }
  return (
    <View>
      <View style={{backgroundColor:'#fff',height:'80px',lineHeight:'80px'}}>
        <View className='iconfont icon-xiangzuo' style={{position:'absolute',top:'0',left:'0',fontSize:'22px',paddingTop:'6px',display:'flex'}}
              onClick={()=>Taro.navigateBack()}>
          <View style={{fontSize:'14px',paddingLeft:'4px'}}>服务范围</View>
        </View>
        <View style={{textAlign:'center',width:'100%'}}></View>
      </View>
      <View className='box'>
        <View className='top'>
          <View>服务半径</View>
          <View>3KM</View>
        </View>
        <Map className='map'  latitude={23.099994} longitude={113.324520} circles={[15]} id='myMap'>
        </Map>
      </View>
    </View>
  );
}

export default Index;
